﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HyperPin_Database_Editor
{
    public partial class HPExitSettings : HPSettingsPanel
    {
        static string iniEnableExitScreen = "Enable_Exit_Screen";
        static string iniExitHyperPin = "Exit_HyperPin";
        static string iniShutdown = "Shutdown";
        static string iniEnableShortcut = "Enable_Shortcut";
        static string iniShortcutAction = "Shortcut_Action";
        static string iniShortcutTime = "Shortcut_Time";

        public HPExitSettings()
        {
            InitializeComponent();
        }


        protected void updateOptionalControls()
        {
            checkExitHyperPin.Enabled = checkEnableExitScreen.Checked;
            checkShutdown.Enabled = checkEnableExitScreen.Checked;
            checkEnableShortcut.Enabled = checkEnableExitScreen.Checked;

            bool enableShortcutControls = checkEnableExitScreen.Checked & checkEnableShortcut.Checked;
            labelShortcutAction.Enabled = enableShortcutControls;
            comboShortcutAction.Enabled = enableShortcutControls;
            labelShortcutTime.Enabled = enableShortcutControls;
            numericShortcutTime.Enabled = enableShortcutControls;
        }

        public override void doLoadSettings()
        {
            checkEnableExitScreen.Checked = readSettingBool(iniEnableExitScreen, true);
            checkExitHyperPin.Checked = readSettingBool(iniExitHyperPin, true);
            checkShutdown.Checked = readSettingBool(iniShutdown, true);
            checkEnableShortcut.Checked = readSettingBool(iniEnableShortcut, true);
            comboShortcutAction.Text = readSetting(iniShortcutAction, "Exit");
            numericShortcutTime.Value = readSettingInt(iniShortcutTime, 3);

            updateOptionalControls();
        }

        public override void doSaveSettings()
        {
            writeSettingBool(iniEnableExitScreen, checkEnableExitScreen.Checked);
            writeSettingBool(iniExitHyperPin, checkExitHyperPin.Checked);
            writeSettingBool(iniShutdown, checkShutdown.Checked);
            writeSettingBool(iniEnableShortcut, checkEnableShortcut.Checked);
            writeSetting(iniShortcutAction, comboShortcutAction.Text);
            writeSettingInt(iniShortcutTime, (int)numericShortcutTime.Value);
        }

        private void checkEnableExitScreen_CheckedChanged(object sender, EventArgs e)
        {
            updateOptionalControls();
        }

        private void checkEnableShortcut_CheckedChanged(object sender, EventArgs e)
        {
            updateOptionalControls();
        }
    }
}
